<?php
namespace app\login\controller;

use think\Controller;

class Apppage extends Controller 
{

	/**
	 * 注册页面
	 * @author 秋水
	 * @DateTime 2018-12-31T22:03:11+0800
	 */
	public function register()
	{
		$share_ma = input('share_ma', '');
		$user = db('user')->where(['share_ma'=>$share_ma])->find();

		$this->assign('share_ma', $share_ma);
		return $this->fetch();
	}

	/**
	 * 发送验证码
	 * @author 秋水
	 * @DateTime 2018-12-31T22:03:32+0800
	 */
	public function sendSms()
	{
		$url = input('url', '');

		$r = file_get_contents($url);
		$result = json_decode($r);

		return json($result);
	}

	/**
	 * app下载页面
	 * @author 秋水
	 * @DateTime 2018-12-31T22:50:53+0800
	 */
	public function download()
	{
		$url = model('todoConfig')->where(['title'=>'androidurl'])->find();
		$iosurl = model('todoConfig')->where(['title'=>'iosurl'])->find();

		if(!$url) {
			$dlurl = 'http://downloadpkg.apicloud.com/app/download?path=http://A6090755351798.qiniucdn.apicloud-system.com/0d43e74f87add7d5b21428514f0d2ee1_d';
		} else {
			$dlurl = $url['value'];
		}
		if(!$iosurl) {
			$iosdlurl = 'https://fir.im/pkaw';
		} else {
			$iosdlurl = $iosurl['value'];
		}
		
		$this->assign('iosdlurl', $iosdlurl);
		$this->assign('dlurl', $dlurl);
		return $this->fetch();
	}

	/**
	 * 分享二维码页面
	 * @author 秋水
	 * @DateTime 2018-12-31T22:50:53+0800
	 */
	public function sharePage()
	{
		$shareMa = input('share_ma', '');
		$this->assign('share_ma', $shareMa);
		return $this->fetch();
	}

	/**
	 * 生成分享图片
	 * @author 秋水
	 * @DateTime 2019-01-09T09:31:41+0800
	 */
	public function shareimg()
	{
		$shareMa = input('share_ma', '');
		$this->assign('share_ma', $shareMa);
		return $this->fetch();
	}

	/**
	 * 远程获取二维码
	 * @author 秋水
	 * @DateTime 2019-01-09T10:44:55+0800
	 */
	public function getimg()
	{
		$share_ma = input('share_ma','');
		$downloadurl = db('todo_config')->where(['title'=>'downloadurl'])->find();
		$text = 'http://'.$downloadurl['value'].'/login/apppage/register?share_ma='.$share_ma;
		$content = file_get_contents('http://api.k780.com:88/?app=qr.get&data='.$text);
		echo $content;
	}

	/**
	 * 二维码展示
	 * @author 秋水
	 * @DateTime 2019-03-16T17:46:21+0800
	 */
	public function qrcode()
	{
		$text = input('text', '');
		$url = 'http://api.k780.com:88/?app=qr.get&data='.$text;

		echo file_get_contents($url);
	}
}